home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / FALCON / ACC / DRIVERS.ACC / GEMSKEL.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  4.6 KB  |  224 lines

  1. /* ================================================================
  2.  * FILE: GEMSKEL.C
  3.  * ================================================================
  4.  * DATE: November 20, 1992
  5.  * DESCRIPTION: GEM Application Skeleton
  6.  */
  7.  
  8.  
  9. /* INCLUDES 
  10.  * ================================================================
  11.  */
  12. #include <sys\gemskel.h>
  13. #include <stdlib.h>
  14. #include <tos.h>
  15.  
  16.  
  17. /* DEFINES
  18.  * ================================================================
  19.  */
  20. #define AP_TERM        50    /* NEW AES Call! */
  21.  
  22.  
  23.  
  24. /* EXTERNS
  25.  * ================================================================
  26.  */
  27. int  open_vwork( void );    /* From FSM.C */
  28. void close_vwork( void );
  29.  
  30.  
  31.  
  32. /* GLOBALS
  33.  * ================================================================
  34.  */
  35.  
  36. /* VDI arrays */
  37. int    contrl[12], intin[128], intout[128], ptsin[128], ptsout[128],
  38.     work_in[12], work_out[57];
  39. int    phys_handle, vhandle, xres, yres;
  40.  
  41.  
  42. /* AES variables */
  43. int    AES_Version; 
  44. int     gl_ncolors;
  45. int    gl_apid, gl_hchar, gl_wchar, gl_hbox, gl_wbox;
  46. GRECT    desk;
  47. OBJECT    *menu;
  48.  
  49.  
  50. /* null structures */
  51. GRECT    grect0 = { 0, 0, 0, 0 };
  52. MOBLK    moblk0 = { 0, 0, 0, 0, 0 };
  53. MFDB    mfdb0 = { NULL, 0, 0, 0, 0, 0, 0, 0, 0 };
  54.  
  55.  
  56. /* Locals used for evnt_multi input, can be set via set_events()
  57.  * ================================================================
  58.  */
  59. static    int    ev_mask=0, ev_clicks=0, ev_bmask=0, ev_bstate=0;
  60. static    MOBLK    ev_m1 = { 0, 0, 0, 0, 0 };
  61. static    MOBLK    ev_m2 = { 0, 0, 0, 0, 0 };
  62. static    long    ev_time=0L;
  63.  
  64.  
  65. /* FUNCTIONS
  66.  * ================================================================
  67.  */
  68.  
  69.  
  70. /*
  71.  * main()
  72.  * ================================================================
  73.  */
  74. void
  75. main( void )
  76. {
  77.     int    event, msg[8], key, nclicks;
  78.     MRETS    mrets;
  79.  
  80.  
  81. /*
  82.  * See if we were run from the AUTO folder...
  83.  */
  84.         gl_apid = appl_init();
  85.  
  86.     /* Get the AES version #.  TOS 3.0 is TT TOS */
  87.     AES_Version = _GemParBlk.global[0];
  88. /*
  89.  * Set up work_in to initialize VDI functions to useful values,
  90.  * Get the physical workstation handle from the AES, then
  91.  * open a virtual workstation and get our AES work area's extent.
  92.  */
  93.     phys_handle = graf_handle(&gl_wchar,&gl_hchar,&gl_wbox,&gl_hbox );
  94.  
  95.     Wind_get( 0, WF_WORKXYWH, ( WARGS *)&desk );
  96.     
  97.     /* Call initialization hooks */
  98.     rsrc_init();
  99.  
  100.  
  101.     if( !open_vwork() )
  102.          gem_exit( -1 );
  103.            
  104.     close_vwork();
  105.   
  106.     gl_ncolors = work_out[13];
  107.     xres       = work_out[0];
  108.     yres       = work_out[1];
  109.     vhandle = 0;
  110.  
  111.     
  112.     wind_init();
  113.     evnt_init();
  114.     
  115.     /* Main event loop */
  116.     do
  117.     {
  118.  
  119.         event = Evnt_multi( ev_mask, ev_clicks, ev_bmask, ev_bstate,
  120.                     &ev_m1, &ev_m2, ( WORD *)msg, ev_time,
  121.                     &mrets,(WORD *)&key,(WORD *)&nclicks );
  122.         wind_update( BEG_UPDATE );
  123.         
  124.  
  125.     /* Dispatch events.
  126.      * It is possible to get more than one event at a time, so if the
  127.      * order of event handling is important to you, change the order
  128.      * in which they're handled here.
  129.      */
  130.         if( event & MU_MESAG )
  131.             switch( msg[0] ) {
  132.  
  133.                 case MN_SELECTED:
  134.                 break;
  135.  
  136.                 case WM_REDRAW:
  137.                 case WM_TOPPED:
  138.                 case WM_CLOSED:
  139.                 case WM_FULLED:
  140.                 case WM_ARROWED:
  141.                 case WM_HSLID:
  142.                 case WM_VSLID:
  143.                 case WM_SIZED:
  144.                 case WM_MOVED:
  145.                 case WM_NEWTOP:
  146.                     do_windows( msg, &event );
  147.                 break;
  148.  
  149.                 case AC_OPEN:
  150.                     acc_open( msg );
  151.                 break;
  152.                 
  153.                 case AP_TERM:
  154.                 case AC_CLOSE:
  155.                     acc_close( msg );
  156.                 break;
  157.  
  158.                 default:
  159.                     break;
  160.             } /* switch */
  161.         /* MU_MESAG */
  162.  
  163.         wind_update( END_UPDATE );
  164.  
  165.     /*
  166.      * Event handling routines zero out the event variable
  167.      * to exit the application.
  168.      */
  169.     } while( event );
  170.  
  171.     gem_exit( 0 );
  172. }
  173.  
  174.  
  175. /* gem_exit()
  176.  * ================================================================
  177.  * Clean exit.
  178.  */
  179. void
  180. gem_exit( int code )
  181. {
  182.     int ignore[8];
  183.  
  184. /*
  185.  * Go into an endless loop if we're a desk accessory...
  186.  */
  187.     if( !_app ) for(;;) evnt_mesag( ignore );
  188.  
  189. /*
  190.  * Otherwise, clean up and call the exit hooks
  191.  */
  192.     wind_update( END_UPDATE );
  193.     close_vwork();
  194.     wind_exit();   
  195.     appl_exit();
  196.     exit( code );
  197. }
  198.  
  199.  
  200. /*
  201.  * evnt_set()
  202.  * ================================================================
  203.  * Set parameters for main evnt_multi.
  204.  */
  205. void
  206. evnt_set( int mask, int clicks, int bmask, int bstate,
  207.       MOBLK *m1, MOBLK *m2, long time )
  208. {
  209.     if( !mask ) gem_exit( -1 );
  210.  
  211.     if( mask != -1 )    ev_mask = mask;
  212.     if( clicks != -1 )    ev_clicks = clicks;
  213.     if( bmask != -1 )    ev_bmask = bmask;
  214.     if( bstate != -1 )    ev_bstate = bstate;
  215.     if( m1 != NULL )    ev_m1 = *m1;
  216.     if( m2 != NULL )    ev_m2 = *m2;
  217.     if( time != -1L )    ev_time = time;
  218. }
  219.  
  220.  
  221.  
  222.  
  223.  
  224.